package com.kaifamiao.servlet;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class PrimaryServlet extends GenericServlet {

    @Override
    public void init() throws ServletException {
        this.log( "初始化[" + this +"]" );
    }

    @Override
    public void service(ServletRequest req, ServletResponse resp)
            throws ServletException, IOException {
        this.log( "[" + this + "]提供服务" );
        // 设置响应对象的MIME类型
        resp.setContentType( "text/html" );
        // 获得向响应对象缓冲区输出数据的字符打印流
        PrintWriter out = resp.getWriter();
        out.println( "<h1>" );
        out.println( "I am PrimaryServlet instance." );
        out.println( "</h1>" );
    }

}
